﻿<?php
require 'Model.php';
	class UserModel extends Model{
		function __Construct(){
			parent::__Construct();
			$this->mod = 'users';
			$this->model='comments';
			$this->mm='cartoontype';
		}



















function getcommentsid($id)
{
	$sql="select * from comments where cid=".$id;
	$data = $this->conn->query($sql);
	      	return $data;
}
function commentslist()
{
	$sql="select * from comments";
	$data=$this->conn->query($sql);

	return $data;
}
function commentsdel($id)
{
	$sql="delete from  comments where cid=".$id;
	$data=$this->conn->query($sql);
	return $data;
}
	function addcomments($data){

			  $one = array(
					'cid' => trim($data['cid']),  
					'content' => $data['content'],
					'cdate' => $data['cdate'],
					'uid' => $data['uid'],
					'id' => $data['id'], 
			  	);
			  $keys = implode(',',array_keys($one));
			  $values = implode("','", array_values($one));
			  $sql="insert into {$this->model} ({$keys}) VALUES ('{$values}')";
			  //执行SQL语句
				$result = $this->conn->query($sql);
					return $result;
			  
		}
				function updatecomments($data){
			$one = array(
					'cid' => trim($data['cid']),  
					//'password' => $data['password'],
					'content' => $data['content'],
					'cdate' => $data['cdate'],
					'uid' => $data['uid'],
					'id' => $data['id'],
			  	);	  
			 $sets = '';
			  foreach ($one as $key=>$val){
			        $sets.=$key."='".$val."',";
			    }
			    $sets=rtrim($sets,','); //去掉SQL里的最后一个逗号
			   
			    $sql="UPDATE {$this->model} SET {$sets} where uid=".$data['id'];
			  //执行SQL语句
				$result = $this->conn->query($sql);
					return $result;
			  
		}































function login()
	{
  $username = $_POST["username"];
$pwd = $_POST["password"];
  $sql = "select * from admin where adminname='".$username."' and password='".$pwd."'"; 
  $data = $this->conn->query($sql);
  return $data;
	}
	function adds($data){
			if(!empty($_FILES["pic"]["name"])){
  				$pic = $this->uploadfile('pic','./upload/',array('jpg','gif','png'));
  				}
			  else{
			  	$pic='';
			  }

			  $one = array(
					'uname' => trim($data['username']),  
					'password' => $data['password'],
					'gender' => $data['gender'],
					'birthdate' => $data['birthdate'],
					'hobby' => implode($data['hobby'], ','),
					'degree' => $data['degree'],
					'intro' => $data['intro'],
					'pic'=>$pic
			  	);
			  $keys = implode(',',array_keys($one));
			  $values = implode("','", array_values($one));
			  $sql="insert into {$this->mod} ({$keys}) VALUES ('{$values}')";
			  //执行SQL语句
				$result = $this->conn->query($sql);
					return $result;
			  
		}







function getctid($id)
{
	$sql="select * from cartoontype where tid=".$id;
	$data = $this->conn->query($sql);
	      	return $data;
}
function ctlist()
{
	$sql="select * from cartoontype";
	$data=$this->conn->query($sql);
	return $data;
}
function addctype($data){
			$video = array(		

				'typename' => trim($data['typename']),  
				
				);
			$keys = implode(',',array_keys($video));
			$values = implode("','",array_values($video));
			/*$sql = "insert into cartoons values ('$video[id]','$video[name]','$video[intro]','$video[size]','$video[uid]','$video[uploadtime]','$video[hint]','$video[address]','$video[pic]')";*/
			$sql="insert into cartoontype ({$keys}) VALUES ('{$values}')";
			//echo "$sql";
			$result = $this->conn->query($sql);
			return $result;
		}
/*function  addctype()
{
$typename=$_POST['typename'];
$sql="insert into cartoontype values typename=".$typename;
$data=$this->conn->query($sql);
return $data;
}*/
function updatectype($data)
{
		$one = array(
			'tid'=>$data['tid'],
					'typename' => trim($data['typename']),  
			  	);
			  
			 		  
			 $sets = '';
			  foreach ($one as $key=>$val){
			        $sets.=$key."='".$val."',";
			    }
			    $sets=rtrim($sets,','); //去掉SQL里的最后一个逗号
			   
			    $sql="UPDATE {$this->mm} SET {$sets} where tid=".$data['tid'];
			  //执行SQL语句
				$result = $this->conn->query($sql);
					return $result;
}
function ctdel($id)
{
	$sql="delete from  cartoontype where tid=".$id;
	$data=$this->conn->query($sql);
	return $data;
}


















function getList(){
			$sql = "select * from {$this->mod}";
		    $data = $this->conn->query($sql);
			return $data;
		}  
		function add($data){
			if(!empty($_FILES["pic"]["name"])){
  				$pic = $this->uploadfile('pic','./upload/',array('jpg','gif','png'));
  				}
			  else{
			  	$pic='';
			  }

			  $one = array(
					'uname' => trim($data['username']),  
					'password' => $data['password'],
					'gender' => $data['gender'],
					'birthdate' => $data['birthdate'],
					'hobby' => implode($data['hobby'], ','),
					'degree' => $data['degree'],
					'intro' => $data['intro'],
					'pic'=>$pic
			  	);
			  $keys = implode(',',array_keys($one));
			  $values = implode("','", array_values($one));
			  $sql="insert into {$this->mod} ({$keys}) VALUES ('{$values}')";
			  //执行SQL语句
				$result = $this->conn->query($sql);
					return $result;
			  
		}
		function getOneByID($id){
			$sql = "select * from {$this->mod} where uid=".$id;
		    $result = $this->conn->query($sql);
	      	return $result;
		}

		function update($data){
			$one = array(
					'uname' => trim($data['uname']),  
					//'password' => $data['password'],
					'gender' => $data['gender'],
					'birthdate' => $data['birthdate'],
					'hobby' => implode($data['hobby'], ','),
					'degree' => $data['degree'],
					'intro' => $data['intro'],
			  	);
			if(!empty($_FILES["pic"]["name"])){
  				$pic = $this->uploadfile('pic','./upload/',array('jpg','gif','png'));
  				$one['pic'] = $pic;
  				}
			  
			 		  
			 $sets = '';
			  foreach ($one as $key=>$val){
			        $sets.=$key."='".$val."',";
			    }
			    $sets=rtrim($sets,','); //去掉SQL里的最后一个逗号
			   
			    $sql="UPDATE {$this->mod} SET {$sets} where uid=".$data['id'];
			  //执行SQL语句
				$result = $this->conn->query($sql);
					return $result;
			  
		}

		function del($id){
			$sql = "delete from {$this->mod} where uid=".$id;
			$result = $this->conn->query($sql);
			return $result;
		}
		function search($key){
	$sql = "select * from {$this->mod} where uname like '%{$key}%'";
	$data = $this->conn->query($sql);
	
		return $data;
}

	}
?>